<%
  file = @options.debug ? 'u/ga_debug' : 'ga'
  pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js'

  gaq = []
  gaq << ['_setAccount', "#{@options.tracking_id}"]
  gaq << ['_setDomainName', "#{@options.domain_name}"] if @options.domain_name
  gaq << ['_setAllowLinker', true] if @options.allow_linker
  gaq << ['_gat._anonymizeIp'] if @options.anonymize_ip
  gaq << ['_require', 'inpage_linkid', pluginUrl] if @options.enhanced_link_attribution
  gaq << ['_trackPageview']
%>
var _gaq = _gaq || [];
<%= gaq.map! { |x| "_gaq.push(#{x});" }.join("\n") %>
(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/<%= file %>.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
